package com.suneee.store.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suneee.base.util.ContextHelper;
import com.suneee.orm.GenericDao;
import com.suneee.store.dao.EnterpriseSpecDao;
import com.suneee.store.entity.EnterpriseSpec;

@Repository("enterpriseSpecDao")
public class EnterpriseSpecDaoImpl extends GenericDao<EnterpriseSpec, Integer>implements EnterpriseSpecDao {

	@Override
	public List<EnterpriseSpec> queryEnterpriseSpecBySpecId(Integer specId) {
		// TODO Auto-generated method stub
		String sql = "select * from t_enterprise_spec where spec_id = ? and enterprise_code = ?";
		return this.executeQuery(sql, new Object[]{specId,ContextHelper.getCurrentLoginInfo().getEnterprise().getEnterpriseCode()});
	}

	@Override
	public void deleteEnterpriseSpecBySpecId(List<Integer> specIdList,String enterpriseCode) {
		// TODO Auto-generated method stub
		String sql = "delete from t_enterprise_spec where enterprise_code = ? and spec_id in (";
		for(int i = 0;i < specIdList.size();i++){
			if(i != specIdList.size() - 1)
				sql += specIdList.get(i) + ",";
			else
				sql += specIdList.get(i);
		}
		sql += ")";
		this.executeUpdate(sql, enterpriseCode);
	}

	@Override
	public EnterpriseSpec getEnterpriseSpecByName(String enterpriseCode, Integer specId, String specValue) {
		// TODO Auto-generated method stub
		String sql = "select * from t_enterprise_spec where spec_id = ? and enterprise_code = ? and spec_value = ?";
		Object[] args = new Object[]{specId,enterpriseCode,specValue};
		List<EnterpriseSpec> list = this.executeQuery(sql, args);
		if(list == null || list.isEmpty())
			return null;
		return list.get(0);
	}

}
